﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Globalization;

namespace ChrizNet.Localization
{
    public class LocalizationManager
    {
        #region Fields
        /// <summary>
        /// The object to access the localized resources.
        /// </summary>
        private static FrameworkElement m_frameworkElement = new StringResources();
        #endregion Fields

        #region DirectBinding Properties
        //The direct binding properties only needed for XAML direct binding.
        //Use GetLocalizedString method to get String in codes behind.
        public static String MenuFile 
        { 
            get { return "File"; } 
        }
        #endregion 

        #region Methods
        /// <summary>
        /// Gets the localized String by providing key.
        /// </summary>
        /// <param name="key">Key to access the localized String.</param>
        /// <returns>Localized String.</returns>
        public static String GetLocalizedString(String key)
        {
#if SILVERLIGHT
            //Silverlight does not support TryFindResource. Use conventional way.
            if (element.Resources.Contains(key))
            {
                return element.Resources[key] as String;
            }
            return String.Empty;
#else

            return m_frameworkElement.TryFindResource(key) as String;
#endif
        }
        #endregion Methods
    }
}
